/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package networkrespnse;

import core.ParameterDecoder;
import core.Statistic;
import java.util.Vector;
import utils.Utils;

/**
 *
 * @author Kvest
 */
public class TaxiParkingStatisticResponse extends Response
{
    private Vector statistics;
    
    public TaxiParkingStatisticResponse(byte[] data)
    {
        super(TAXI_PARKING_STATISTIC_RESPONSE);
        statistics = new Vector();

        parse(data);
    }


    protected void parse(byte[] data)
    {
        byte[] body,temp;
        int index,count;
        //��������  body
        body = ParameterDecoder.getTransferBody(data);

        //������������� ��������
        temp = new byte[4];
        index = 0;
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        index += Utils.byteToInt(temp);

        //������ �������
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        count =  Utils.byteToInt(temp);

        //��������� ������
        for (int j=0;j<count;j++)
        {
                for (int i=0;i<4;i++)
                {
                        temp[i] = body[index++];
                }
                addStatistic(new Statistic(Utils.byteToInt(temp)));
        }

        //������ 2 �������
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        count =  Utils.byteToInt(temp);
        //��������� ������ 2
        temp[2] = 0;
        temp[3] = 0;
        for (int j = 0; j < count; ++j)
        {
                for (int i=0;i<2;i++)
                {
                        temp[i] = body[index++];
                }
                getStatistic(j).setCount(Utils.byteToInt(temp));
        }

        //Список позывных на стоянке
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        count =  Utils.byteToInt(temp);
        int bytesCount = 0;
        for (int j=0;j<count;j++)
        {
            temp = new byte[4];
            for (int i=0;i<4;i++)
            {
                temp[i] = body[index++];
            }
            bytesCount =  Utils.byteToInt(temp);
            temp = new byte[bytesCount];
            for (int i=0;i<bytesCount;++i)
            {
                temp[i] = body[index++];
            }
            getStatistic(j).setQueue(Utils.byteToString(temp));
        }
    }

    public void addStatistic(Statistic value)
    {
        statistics.addElement(value);
    }

    public Statistic getStatistic(int index)
    {
        return (Statistic)statistics.elementAt(index);
    }

    public Vector getStatistics()
    {
        return statistics;
    }
}
